using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class ValueTypeAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public ValueTypeAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{"AD","CE","CF","CK","CN","CP","CX","DT","ED","FT","ID","MO","NM","PN","RP","SN","ST","TM","TN","TS","TX","XAD","XCN","XON","XPN","XTN"};
						validVersionCodes[HL7Version.v231] = new string[]{"AD","CE","CF","CK","CN","CP","CX","DT","ED","FT","MO","NM","PN","RP","SN","ST","TM","TN","TS","TX","XAD","XCN","XON","XPN","XTN"};
						validVersionCodes[HL7Version.v24] = new string[]{"AD","CE","CF","CK","CN","CP","CX","DT","ED","FT","MO","NM","PN","RP","SN","ST","TM","TN","TS","TX","XAD","XCN","XON","XPN","XTN"};
						validVersionCodes[HL7Version.v25] = new string[]{"AD","CE","CF","CK","CN","CP","CX","DT","ED","FT","MO","NM","PN","RP","SN","ST","TM","TN","TS","TX","XAD","XCN","XON","XPN","XTN"};
						validVersionCodes[HL7Version.v251] = new string[]{"AD","CE","CF","CK","CN","CP","CX","DT","ED","FT","MO","NM","PN","RP","SN","ST","TM","TN","TS","TX","XAD","XCN","XON","XPN","XTN"};
						validVersionCodes[HL7Version.v26] = new string[]{"AD","CWE","CF","CK","CN","CP","CX","DT","ED","FT","MO","NM","PN","RP","SN","ST","TM","TN","DTM","TX","XAD","XCN","XON","XPN","XTN"};
						validVersionCodes[HL7Version.v27] = new string[]{"AD","CNE","CWE","CF","CK","CN","CP","CX","DR","DT","DTM","ED","FT","ID","IS","MA","MO","NA","NM","PN","RP","SN","ST","TM","TN","TX","XAD","XCN","XON","XPN","XTN"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{"Address","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date","Encapsulated Data","Formatted Text (Display)","Coded Value","Money","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Time Stamp (Date & Time)","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
						validVersionDescriptions[HL7Version.v231] = new string[]{"Address","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date","Encapsulated Data","Formatted Text (Display)","Money","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Time Stamp (Date & Time)","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Address","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date","Encapsulated Data","Formatted Text (Display)","Money","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Time Stamp (Date & Time)","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Address","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date","Encapsulated Data","Formatted Text (Display)","Money","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Time Stamp (Date & Time)","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Address","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date","Encapsulated Data","Formatted Text (Display)","Money","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Time Stamp (Date & Time)","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Address","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date","Encapsulated Data","Formatted Text (Display)","Money","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Time Stamp (Date & Time)","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Address","Coded with No Exceptions","Coded Entry","Coded Element With Formatted Values","Composite ID With Check Digit","Composite ID And Name","Composite Price","Extended Composite ID With Check Digit","Date/Time Range","Date","Time Stamp (Date & Time)","Encapsulated Data","Formatted Text (Display)","Coded Value for HL7 Defined Tables","Coded Value for User-Defined Tables","Multiplexed Array","Money","Numeric Array","Numeric","Person Name","Reference Pointer","Structured Numeric","String Data.","Time","Telephone Number","Text Data (Display)","Extended Address","Extended Composite Name And Number For Persons","Extended Composite Name And Number For Organizations","Extended Person Name","Extended Telecommunications Number"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
